package com.itheima.aduit;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.itheima.common.utils.IdWorker;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;

@EnableFeignClients
@EnableDiscoveryClient
@EnableEurekaClient
@SpringBootApplication(
		exclude = {org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class,
				org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration.class
		} )
public class AduitApplication {
	public static void main(String[] args) {
		SpringApplication.run(AduitApplication.class, args);
	}

	@Bean
	public IdWorker idWorker(){
		return new IdWorker();
	}


	/**
	 * 为了解决activiti对象转换json的问题
	 * 		通过自定义json转换器的形式完成
	 * 			通过使用fastjson替换默认的Jackson转换json
	 * 	        在转换器中过滤了identityLinks属性
	 * @return
	 */
	@Bean
	public HttpMessageConverters fastJsonHttpMessageConverters() {
		FastJsonHttpMessageConverter fjc = new FastJsonHttpMessageConverter();
		FastJsonConfig config = new FastJsonConfig();
		config.setSerializerFeatures(SerializerFeature.PrettyFormat);
		SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
		filter.getExcludes().add("identityLinks");
		config.setSerializeFilters(filter);
		fjc.setFastJsonConfig(config);
		HttpMessageConverter<?> converter = fjc;
		return new HttpMessageConverters(converter);
	}



}
